<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\bootstrap\Modal;
/* @var $this yii\web\View */
/* @var $searchModel app\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Wm Users');
$this->params['breadcrumbs'][] = $this->title;

?>


<div class="wm-user-index">
    <?php

    Modal::begin([
        'header' => '<h2>Hello world</h2>',
    ]);
    echo 'Say hello...';
    Modal::end();
    ?>


    <div class="modal fade" id="ajax">
        <div class="modal-dialog">
            <div class="modal-content">

            </div>
        </div>
    </div>


    <p>
        <?php // Html::a(Yii::t('app', 'Create Wm User'), ['create'], ['class' => 'btn btn-success']) ?>
        <?php
        echo Html::a(Yii::t('app', 'Create Wm User'), ['create','ajax'=>1], ['class' => 'btn btn-success','data-toggle'=>'modal','data-target'=>'#ajax'])
        ?>

    </p>

    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
//        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

//            'id',

            [
                'attribute' => 'channels_name',
                'format' => 'raw',
                'value' =>
                    function ($data) {
                        return html::a($data->channels_name,['product/index','WmProductSearch[uid]'=>$data->id],['title' => '审核']);
                    },
            ],
            'productCount',
            'username',
            'password',
            [
                'attribute' => 'status',
                'value' => function ($data) {
                    return \app\models\WmUser::$statuses[$data->status];
                },
            ],
            // 'package_name',

            // 'is_admin',
//             'created_at:datetime',
//            'created_at',
            [
                'attribute' => 'created_at',
                'value' => function ($data) {
                    return date("Y-m-d H:i:s",$data['created_at']);
                },
            ],


            ['class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'options' => ['width' => '120px;'],
                'template' => '{update}{area}{product}{modal}{copy}',
                'buttons' => [
                    'area' => function ($url, $model) {
                        if($model->status==0){
                        return Html::a('<span class="">'.Yii::t('app', 'Disables').'</span>', ['status', 'id' => $model->id,'status'=>1], [
                            'class' => 'glyphicon',
                            'data' => [
                                'confirm' => Yii::t('app', 'Are you sure you want to disable this project?'),
                                'method' => 'post',
                            ],
                        ]);
                        }else{
                            return Html::a('<span class="">'.Yii::t('app', 'Enables').'</span>', ['status', 'id' => $model->id,'status'=>0], [
                                'class' => 'glyphicon',
                                'data' => [
                                    'confirm' => Yii::t('app', 'Are you sure you want to enable this project?'),
                                    'method' => 'post',
                                ],
                            ]);
                        }
                    },
                    'product' => function ($url, $model) {
                            return Html::a('<span class="">'.Yii::t('app', 'Create Wm Product').'</span>', ['product/create', 'id' => $model->id,'ajax'=>1], [
                                'class' => 'glyphicon','data-toggle'=>'modal','data-target'=>'#ajax'.$model->id

                            ]);

                    },
                    'update' => function ($url, $model) {
                        return Html::a('<span class="">'.Yii::t('app', 'Update').'</span>', ['update', 'id' => $model->id,'ajax'=>1], [
                            'class' => 'glyphicon','style'=>'display:block;padding-bottom:5px;','data-toggle'=>'modal','data-target'=>'#ajax'.$model->id

                        ]);

                    },
                    'copy' => function ($url, $model) {
//                        return '<a id="copy-info'.$model->id.'">'.Yii::t('app', 'copy info').'</a>';
                        return Html::a('<span class="">'.Yii::t('app', 'copy info').'</span>', '', [
                            'class' => 'copy-info glyphicon','data-text'=>'登录页面：'.Yii::$app->request->hostInfo.'/index.php  帐号：'.$model->username.'  密码：'.$model->password.''
                        ]);

                    },
                    'modal' => function ($url, $model) {
                        return '<div class="modal fade" id="ajax' . $model->id . '">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                        </div>
                                    </div>
                                </div><div class="modal fade" id="ajax_' . $model->id . '">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                        </div>
                                    </div>
                                </div>';
                    },


                ],
//                'urlCreator' => function ($action, $model, $key, $index) {
//                    if ($action === 'view') {
//                        return ['view', 'id' => $model->id];
//                    } else if ($action === 'update') {
//                        return ['update', 'id' => $model->id];
//                    } else if ($action === 'areas') {
//                        return ['area/index', 'group_id' => $model->id];
//                    }
//                }

                ]
            ],
    ]); ?>
</div>



<?php $this->registerJsFile('/js/jquery-zclip/jquery.zclip.js',['depends'=>'yii\web\YiiAsset','position'=>\yii\web\View::POS_HEAD]); ?>

<?php $this->registerJs('
$(document).ready(function(){
  $("a.copy-info").each(function(){
        var that=$(this);
        var val =that.data(\'text\');
        $(this).zclip({
            path:\'/js/jquery-zclip/ZeroClipboard.swf\',
            copy:val
        });
    });
});

',\yii\web\View::POS_END); ?>
